/* -----------------------------------------------------------------------------
 * PROJECT    : net.lwf
 * FILE       : ShapeDisplayAction.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Dec 23, 2008       Raghu Sarraff			       Created
 */
package lwf.web.struts.action.shapes;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lwf.handler.IProcessHandler;
import lwf.handler.english.WordHandler;
import lwf.handler.shape.ShapeDisplayHandler;
import lwf.web.struts.action.english.WordAction;
import lwf.web.struts.action.form.english.WordDisplayActionForm;

import net.lwf.util.web.WebUtil;
import net.lwf.web.constant.IPageTitle;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


/**
 * Type the class description here
 *  
 */
public class ShapeDisplayAction extends WordAction {
	
	//Remove this if you have a common class that removes the session variables.
	public ActionForward home(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		//WordDisplayActionForm swform = (WordDisplayActionForm) form;
		WebUtil.removeAttribute(request, "end");
		WebUtil.removeAttribute(request, "start");
		WebUtil.removeAttribute(request, "shapes");

		return mapping.findForward("home");
	} //home

	/**
	 * @see net.lwf.web.struts.action.english.WordAction#getHandler(javax.servlet.http.HttpServletRequest, org.apache.struts.action.ActionForm)
	 */
	public WordHandler getHandler(HttpServletRequest request, ActionForm form) {
        int start = getStart(request);
        int end = getEnd(request);
        WordDisplayActionForm wdaf = (WordDisplayActionForm) form;
		return new ShapeDisplayHandler(start, end, getShapeData(request));
	}

	/**
	 * @see net.lwf.web.struts.action.english.WordAction#checkGrade(javax.servlet.http.HttpServletRequest, org.apache.struts.action.ActionForm)
	 */
	public void checkGrade(HttpServletRequest request, ActionForm form) {
	}

	/**
	 * @see net.lwf.web.struts.action.english.WordAction#getDisplayRows(org.apache.struts.action.ActionForm)
	 */
	public int getDisplayRows(ActionForm form) {
		return 1;
	}
	
	private List getShapeData(HttpServletRequest request) {
        int start = getStart(request);
        int end = getEnd(request);
        //above remove later
		List lstData = (List) WebUtil.getAttribute(request, "shapes");
		if(lstData == null) {
			lstData = ShapeDisplayHandler.generateShapes();
			WebUtil.setAttribute(request, "shapes", lstData);
		}
		return lstData;
	}

	@Override
	public IProcessHandler getHandler(HttpServletRequest request) {
		return null;
	}
	
	@Override
	public String getPageTitle() {
		return IPageTitle.SHAPES;
	}

	@Override
	public String getMainTitle() {
		return null;
	}

	@Override
	public String getPdfLink() {
		return null;
	}

	@Override
	public String getQuizLink() {
		return null;
	}

}

